package fr.ifisher.service.implementation;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import fr.ifisher.dao.inter.IUserDao;
import fr.ifisher.dto.UserDto;
import fr.ifisher.entity.User;
import fr.ifisher.service.inter.IUserService;

@Service
public class UserService implements IUserService {

	// private final Logger LOGGER = LoggerFactory.getLogger(UserService.class);

	@Autowired
	private IUserDao userDao;

	@Override
	@Transactional
	public UserDto read(Long id) {

		User user = userDao.read(id);
		UserDto userDto = new UserDto();
		userDto.setId(user.getId());
		userDto.setName(user.getName());

		return userDto;
	}

	@Override
	@Transactional
	public List<UserDto> listUser() {

		List<User> listUser = userDao.getAll();

		List<UserDto> listToReturn = new ArrayList<UserDto>();

		for (User user : listUser) {
			UserDto userDto = new UserDto();
			userDto.setId(user.getId());
			userDto.setName(user.getName());

			listToReturn.add(userDto);
		}

		return listToReturn;
	}

}
